// EllipseProperties.cpp : implementation file
//

#include "stdafx.h"
#include "resourcemake.h"
#include "EllipseProperties.h"

#include "resourcemakeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEllipseProperties dialog


CEllipseProperties::CEllipseProperties(CWnd* pParent /*=NULL*/)
	: CDialog(CEllipseProperties::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEllipseProperties)
	m_LineStyle = _T("");
	m_LineWidth = _T("");
	//}}AFX_DATA_INIT
	m_bFill = false;
}


void CEllipseProperties::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEllipseProperties)
	DDX_Control(pDX, IDC_BUTTON_COLOR, m_BtnColor);
	DDX_Control(pDX, IDC_BUTTON_BRUSHCOLOR, m_BtnBrushColor);
	DDX_CBString(pDX, IDC_LINESTYLE, m_LineStyle);
	DDX_CBString(pDX, IDC_LINEWIDTH, m_LineWidth);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEllipseProperties, CDialog)
	//{{AFX_MSG_MAP(CEllipseProperties)
	ON_BN_CLICKED(IDC_BUTTON_BRUSHCOLOR, OnButtonBrushcolor)
	ON_BN_CLICKED(IDC_BUTTON_COLOR, OnButtonColor)
	ON_EN_CHANGE(IDC_LINEWIDTH, OnChangeLinewidth)
	ON_CBN_SELCHANGE(IDC_LINEWIDTH, OnSelchangeLinewidth)
	ON_WM_CTLCOLOR()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEllipseProperties message handlers

BOOL CEllipseProperties::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CString str;
	for(int i=0;i<10;i++)
	{
		str.Format("%d",i+1);
		((CComboBox*)GetDlgItem(IDC_LINEWIDTH))->InsertString(i,str);
	}

	// TODO: Add extra initialization here

	return TRUE;  // return TRUE unless you set the focus to a control
}

void CEllipseProperties::OnButtonBrushcolor() 
{
	// TODO: Add your control notification handler code here
	( (CResourcemakeDlg*) AfxGetApp()->m_pMainWnd) ->m_IsSaveSsml = FALSE;

	CColorDialog dlg(m_BrushColor); 
	if (dlg.DoModal()==IDOK)
	{
		m_bFill = true;
		m_BrushColor=dlg.GetColor();
		CString str_RGB;
		str_RGB.Format("%d:%d:%d",GetRValue(m_BrushColor),GetGValue(m_BrushColor),GetBValue(m_BrushColor));
		this->m_BtnBrushColor.SetWindowText(str_RGB);
		m_pCurrObj->m_bFill = m_bFill;
		m_pCurrObj->BrushColor = m_BrushColor;
		GetDlgItem(IDC_FILLCOLOR_SHOW)->RedrawWindow();
		((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_ddd->Invalidate();
	}	
}

void CEllipseProperties::OnButtonColor() 
{
	// TODO: Add your control notification handler code here
	( (CResourcemakeDlg*) AfxGetApp()->m_pMainWnd) ->m_IsSaveSsml = FALSE;

	CColorDialog dlg(m_LineColor); 
	if (dlg.DoModal()==IDOK)
	{
		m_LineColor=dlg.GetColor();
		CString str_RGB;
		str_RGB.Format("%d:%d:%d",GetRValue(m_LineColor),GetGValue(m_LineColor),GetBValue(m_LineColor));
		this->m_BtnColor.SetWindowText(str_RGB);
		m_pCurrObj->LineColor = m_LineColor;
		((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_ddd->Invalidate();
	}
}

void CEllipseProperties::OnChangeLinewidth() 
{
	( (CResourcemakeDlg*) AfxGetApp()->m_pMainWnd) ->m_IsSaveSsml = FALSE;

	GetDlgItemText(IDC_LINEWIDTH,m_LineWidth);
	m_pCurrObj->LineWidth = atoi(m_LineWidth);
	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_ddd->Invalidate();
}

void CEllipseProperties::OnSelchangeLinewidth() 
{
	int m = ((CComboBox*)GetDlgItem(IDC_LINEWIDTH))->GetCurSel();
	m_LineWidth.Format("%d",m+1);
	m_pCurrObj->LineWidth = m+1;
	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_ddd->Invalidate();
}

HBRUSH CEllipseProperties::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a different brush if the default is not desired
	if(nCtlColor==IDC_FILLCOLOR_SHOW)
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(m_BrushColor);
	}
	return hbr;
}

void CEllipseProperties::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CDialog::OnPaint() for painting messages
	CRect rt;   
	GetDlgItem(IDC_FILLCOLOR_SHOW)->GetWindowRect(rt);   
	ScreenToClient(rt);   
	dc.FillSolidRect(rt,m_BrushColor);   

}
